$(function () {
  $("#tabs").tabs({
    selected:0
  });
  
  $(':radio').css({height:15});
  
  $.get('cats.action',"",processCatsResponse);

  $("#accordion").accordion({fillSpace:true, active:0});
  $("#accordionResizer").resizable({resize:function () {
    $("#accordion").accordion("resize");
  }, minHeight:500});

  $("#sortable_step1_2").sortable({placeholder:"ui-state-highlight", stop:function (event, ui) {
    transBePromotedToServer();
  }});
  
  $("#sortable_step1_2").disableSelection();
  
});

function transBePromotedToServer(){
  var data={
        "ipro.to_be_promoted": $("#sortable_step1_2").html()
      };
  $.post("ipro.action",data,null,'json');
}

function transPromoteToServer(){
  var data={
        "ipro.to_promote": $('#promot_resp').html()
      };
  $.post("ipro.action"+$("#jsession_id").val(),data,null,'json');
}

function processCatsResponse(data, status) {
  var sellerCats = data.sellerCats;
  var sellerCatsSelect = "<option value='all_cats'>---所有宝贝---</option>";
  var sellerCatsCheckbox = '';
  var count = 1;
  $.each(sellerCats, function (catref, cat) {
    var cat_name = cat.name;
    var seller_cats_checkbox_style ='seller_cats_checkbox2';
    if(cat.isLeaf=='2'){
      cat_name = '└'+cat.name;
    }
    if(cat.isLeaf=='0'){
      sellerCatsSelect += "<optgroup label="+ cat_name + "></optgroup>";
    }else{
      if(count==1){
        seller_cats_checkbox_style = 'seller_cats_checkbox1';
        count++;
      }
      sellerCatsSelect += "<option value='" + cat.cid + "'>"+ cat_name + "</option>";
      sellerCatsCheckbox += "<input type=checkbox class = "+seller_cats_checkbox_style+" name='seller_cats_promote' value="+cat.cid+">"+cat.name;
    } 
  });
  sellerCatsSelect += "<option value ='-1'>未分类宝贝</option>";
  $("#sellerCats").html(sellerCatsSelect);
  $("#seller_cats_2").html(sellerCatsSelect);
  $("#seller_cats_promote_div").html(sellerCatsCheckbox);
}

function formatItemPic(cellvalue, options, rowObject){
  return "<img src='"+cellvalue+"_60x60.jpg'></img>";
}

function formateadorLink(cellvalue, options, rowObject) {
   var title = "<span style='text-decoration:underline;font-size:13px;color:blue;'>"+cellvalue+"</span>"
   return "<a href=http://item.taobao.com/item.htm?id="+ rowObject.iid + " target='_blank'>" + title + "</a>";
}

function setImageCellHeight(gridName) { 
    var ids = $("#"+gridName).getDataIDs(); 
    for (var i = 0; i < ids.length; i++) { 
      var cl = ids[i]; 
      $("#"+gridName).setRowData(ids[i],false, {height: 50}); 
    } 
}

function setCellHeight(gridName,height) { 
    var ids = $("#"+gridName).getDataIDs(); 
    for (var i = 0; i < ids.length; i++) { 
      var cl = ids[i]; 
      $("#"+gridName).setRowData(ids[i],false, {height: height}); 
    } 
}

function builderSimpleTitle(ret){
  var title = ret.frank_title;
  if(title.length>18){
     title= title.slice(0,18)+"...";
  }
  var item_url = 'http://item.taobao.com/item.htm?id='+ret.iid;
  var title_html="<a href='"+item_url+"' style='text-decoration:underline;font-size:13px;color:blue;height:35px'>"+title+"</a>";
  return title_html;
}

